<html>

<style>
    * {
        margin: 0;
    }

    #content {
        color: white;
        position: absolute;
        left: -20px;
        top: -10px;
        white-space: pre;
        height: 200px;
        overflow: auto;
    }
</style>

<script type="importmap">
	{
	  "imports": {
		"three": "../../three.js-r151/build/three.module.js",
		"three/addons/": "../../three.js-r151/examples/jsm/"
	  }
	}
</script>

<body>
    <div id="content">
        1. position, scale都是 Three.Vector3类型
        2. rotation是Three.Euler类型
    </div>

    <div id="canvas"></div>

    <script type="module">
        import * as THREE from 'three';
        import { OrbitControls } from 'three/addons/controls/OrbitControls.js';



        // 1. 创建三大件
        // 1.1 三维场景Scene, 类似创建了个世界，三维世界
        const scene = new THREE.Scene();
        const geometry = new THREE.BoxGeometry(1, 1, 1);

        // .load()方法加载图像，返回一个纹理对象Texture
        //纹理贴图加载器TextureLoader
        const texLoader = new THREE.TextureLoader();
        const texture = texLoader.load('./xiaoyan.jpg');

        // MeshBasicMaterial MeshLambertMaterial
        const material = new THREE.MeshLambertMaterial({ 
            // color: 'yellow',
            map: texture, 
        });
        const cube = new THREE.Mesh(geometry, material);
        scene.add(cube);

        const cube1 = new THREE.Mesh(geometry, material);
        cube1.position.set(2, 0, 0)
        scene.add(cube1);

        // 2. 打光
        const light = new THREE.DirectionalLight( 0xFFFFFF );
        light.position.set(6, 0, 3);
        scene.add(light)
        // const helper = new THREE.DirectionalLightHelper( light, 5 );
        // scene.add( helper );
        // scene.add( new THREE.CameraHelper( light.shadow.c );


        // 添加辅助坐标系
        const axesHelper = new THREE.AxesHelper(5);
        scene.add(axesHelper);

        // 1.2 相机
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
        camera.position.set(5, 5, 5)

        // 1.3 渲染器
        const renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);
        let canvasDom = document.getElementById("canvas");
        canvasDom.appendChild(renderer.domElement);

        // 设置相机控件轨道控制器OrbitControls
        new OrbitControls(camera, canvasDom);
        
        function render() {
            renderer.render(scene, camera);
            requestAnimationFrame(render)
        }
        render();

        // 试试不同形状
        const geometry1 = new THREE.SphereGeometry(1.5, 25, 25); //球体
        let cube2 = new THREE.Mesh(geometry1, material)
        cube2.position.z = 3
        scene.add(cube2)


    </script>
</body>

</html>